<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017-10-05
 * Time: 22:38
 */

namespace app\Http\Controllers\Wechat;


use App\Http\Controllers\Controller;
use App\Models\Member;
use App\Models\MemberAccount;
use App\Models\WechatUpload;
use Illuminate\Support\Facades\Session;


class MemberCenterController extends Controller
{
    public function getIndex()
    {
        $query = WechatUpload::query()
            ->where('openid', Session::get('wechat_openid'))
            ->where('status', 0);
        $imageCount = (clone $query)->where('type', 1)->count();
        $videoCount = (clone $query)->where('type', 2)->count();
        $avatar = to_https_url(Session::get('member')->avatar);
        $nickName = Session::get('member')->nickname;
        $member = Member::getByOpenid(Session::get('wechat_openid'));
        $memberAccount = MemberAccount::query()->where('openid', Session::get('wechat_openid'))->first();
        $totalPrice = $memberAccount ? $memberAccount->balance : 0;
        $lockPrice = $memberAccount ? $memberAccount->lock_balance : 0;
        return view('wechat.member-center', compact('imageCount', 'videoCount', 'totalPrice', 'avatar', 'nickName', 'lockPrice', 'member'));
    }
}